{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# [Angles of a Clock（时间的夹角）](https://mp.weixin.qq.com/s/NiIY1IJFiwjRDUxTtIs3cg)\n",
    "\n",
    "Given a time in the format of `hour` and `minute`, calculate the angle of the hour and minute hand on a clock.\n",
    "\n",
    "给定一个时间（小时和分钟），计算时钟上时针与分针之间的夹角。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Algorithm（算法）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "def calcAngle(hour, minute):\n",
    "    minute_towards = 6 * minute\n",
    "    hour_towards = 30 * (hour % 12) + 0.5 * minute\n",
    "    angle = abs(hour_towards - minute_towards)\n",
    "    if angle > 180:\n",
    "        return 360 - angle\n",
    "    else:\n",
    "        return angle"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Test Cases（测试样例）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "75.0"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "calcAngle(3, 30)\n",
    "# 75"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "165.0"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "calcAngle(12, 30)\n",
    "# 165"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
